package com.smartcampusbackend.controller;

import com.smartcampusbackend.service.UserReadStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/user/read-status")
@CrossOrigin(origins = "*")
public class UserReadStatusController {
    @Autowired
    private UserReadStatusService userReadStatusService;

    // 标记为已读
    @PostMapping("/mark-read")
    public Map<String, Object> markAsRead(@RequestParam Integer userId, 
                                         @RequestParam Integer announcementId) {
        int result = userReadStatusService.markAsRead(userId, announcementId);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", result > 0 ? 200 : 500);
        resp.put("message", result > 0 ? "标记成功" : "标记失败");
        return resp;
    }

    // 获取用户阅读状态
    @GetMapping("/user/{userId}")
    public Map<String, Object> getUserReadStatus(@PathVariable Integer userId,
                                                @RequestParam(required = false) String type) {
        List<com.smartcampusbackend.model.UserReadStatus> list = 
            userReadStatusService.getUserReadStatus(userId, type);
        Map<String, Object> resp = new HashMap<>();
        resp.put("code", 200);
        resp.put("data", list);
        return resp;
    }
} 